<?php

/**
 * uniBoard ACP Imagesets page
 *
 * Light and fast forum solution for web 2.0-like communities.
 *
 * @package		uniBoard
 * @author		Rafał Pitoń
 * @license		http://www.gnu.org/licenses/gpl-3.0.html
 * @since		Version 0.1
 * 
 * ------------------------------------------------------------------------
 * 
 * $Date: 2010-09-15 17:35:38 +0000 (Wed, 15 Sep 2010) $
 * $Revision: 61 $
 * $Author: rafio.xudb@gmail.com $
 */

// ------------------------------------------------------------------------

class action_images{
	
	/**
	 * Main class pointer
	 *
	 * @var object
	 */
	
	private $appCore		= NULL;
	
	// ------------------------------------------------------------------------

	/**
	 * Initialise Action
	 *
	 * @param object $appCore
	 */
	
	function __construct( $appCore){
		
		// Store appCore pointer
		$this -> appCore = $appCore;
		
		// Page Help
		$appCore -> output -> page_help = $appCore -> lang['acp_imagesets_list_help'];
		
		// Add language string
		$appCore -> output -> js_vars['l_delete_item_sure'] =  $appCore -> lang['delete_item_sure'];
			
		// Load fields templates
		$appCore -> templates['form_inputs'] = new tpl_form_inputs( $this -> appCore);
		
		// Cache output
		ob_start();
		
		// Open table block
		echo $appCore -> output -> openTableBlock();
		
		// Draw header
		echo $appCore -> output -> tableHeader( array(
			array(
				'left_float width_quarter',
				$appCore -> lang['images_list_set']
			),
			array(
				'right_float width_medium',
				$appCore -> lang['actions']
			),
			array(
				'right_float width_medium',
				$appCore -> lang['images_list_styles']
			)
		));
				
		// Select imageset
		$appCore -> db -> query( 'SELECT i.*, COUNT( s.imageset_id) AS images_users
		FROM ' . DB_PREFIX . 'imagesets i
		LEFT JOIN ' . DB_PREFIX . 'styles s ON  i.imageset_id = s.imageset_id
		GROUP BY i.imageset_id
		ORDER BY i.imageset_name');
		
		// Parse result
		while ( $imageset_result = $appCore -> db -> fetch_assoc())
		{
			// Draw row
			echo $appCore -> output -> tableRow('
				<div class="cell left_float width_longer">
					<b>' . htmlspecialchars( $imageset_result['imageset_name']) . '</b>
				</div>
				<div class="cell left_border right_float width_medium">
					' . $appCore -> output -> toolsPopup( ( $imageset_result['imageset_id'] != 1 || DEVELOPER_MODE ? '<a href="' . $appCore -> adminLink( 'act=edit_imageset&do=details&set=' . $imageset_result['imageset_id']) . '">' . $appCore -> output -> drawImage( 'action_edit', $appCore -> lang['imageset_op_edit']) . ' ' . $appCore -> lang['imageset_op_edit'] . '</a>' : '') . '
					<a href="' . $appCore -> adminLink( 'act=edit_imageset&do=images&set=' . $imageset_result['imageset_id']) . '">' . $appCore -> output -> drawImage( 'action_images', $appCore -> lang['imageset_op_browse']) . ' ' . $appCore -> lang['imageset_op_browse'] . '</a>
					<a href="' . $appCore -> adminLink( 'act=edit_imageset&do=copy&set=' . $imageset_result['imageset_id']) . '">' . $appCore -> output -> drawImage( 'action_copy', $appCore -> lang['imageset_op_copy']) . ' ' . $appCore -> lang['imageset_op_copy'] . '</a>
					<a href="' . $appCore -> adminLink( 'act=edit_imageset&do=export&set=' . $imageset_result['imageset_id']) . '">' . $appCore -> output -> drawImage( 'action_download', $appCore -> lang['imageset_op_export']) . ' ' . $appCore -> lang['imageset_op_export'] . '</a>
					' . ( $imageset_result['imageset_id'] != 1 ? '<a href="' . $appCore -> adminLink( 'act=edit_imageset&do=delete&set=' . $imageset_result['imageset_id']) . '"' . ( $imageset_result['images_users'] > 0 ? '' : ' class="delete_confirm"') . '>' . $appCore -> output -> drawImage( 'action_delete', $appCore -> lang['imageset_op_delete']) . ' ' . $appCore -> lang['imageset_op_delete'] . '</a>' : '')) . '
				</div>
				<div class="cell left_border right_float width_medium center">
					' . $appCore -> number( $imageset_result['images_users']) . '
				</div>');
		}
		
		// Free result
		$appCore -> db -> freeResult();
		
		// Close table block
		echo $appCore -> output -> closeTableBlock();
		
		// New style form start
		echo $appCore -> output -> openForm( $appCore -> adminLink( 'act=new_imageset', true));
		echo $appCore -> output -> openFormBlock( $appCore -> lang['new_imageset_form']);
		
		// Draw field
		echo $appCore -> output -> formItem( $appCore -> lang['new_imageset_form_name'], $appCore -> drawTextInput( 'new_imageset_name'), $appCore -> lang['new_imageset_form_name_expl']);
		
		// New style form close
		echo $appCore -> output -> submitButton( $appCore -> lang['new_imageset_form_submit']);
		echo $appCore -> output -> closeFormBlock();
		echo $appCore -> output -> closeForm();
		
		// Draw output
		$appCore -> output -> draw( $appCore -> lang['acp_imagesets_list'], array( $appCore -> adminLink( 'act=images') => $appCore -> lang['acp_imagesets_list']), ob_get_clean());
				
	}

}